load mnist_knn_test;

k = 7;
s = 100;
n = size(IDX,1);

disp('Building graph...');
Ivec = reshape(repmat((1:n)',1,k),[],1);
IDXvec = reshape(IDX(:,2:k+1),[],1);
clear IDX;
Dvec = reshape(DIST(:,2:k+1).^2,[],1);
clear M;
Dvec = Dvec/max(Dvec);

A = sparse(Ivec,IDXvec,Dvec);
B = adj2inc(A,0);
L = B'*B;
[V,D] = eigs(L,s+1,'sm');
VV = V(:,s:-1:1);
disp('Graph finished!');